<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

include_once("includes/db.inc");
include_once("includes/functions.inc");

session_start();
include_once("includes/session.inc");

ControleAcces("deltemp.php",$login,$pwd,$user_id,session_id());

if ($_GET['action']) $action = $_GET['action'];
if ($_GET['date_in']) $date_in = $_GET['date_in'];
if ($_GET['location_ID']) $location_ID = $_GET['location_ID'];

if ($user_id)
{

$result = biblio_db_query("SELECT login FROM admin WHERE id = $user_id" ,$db);
$myrow = biblio_db_fetch_array($result);
$user = $myrow['login'] ;

include ("includes/header.inc");

  if($action != "del")
  {  
	$requete = "select  distinct t1.date_in,t1.location_ID, t2.local, t2.rangee, t2.biblio from livres as t1 inner join locations as t2 on t2.id = t1.location_ID where temp =1 and del=0";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                echo "<CENTER><H3>";
		echo _("Effacer les livres temporaires entr&eacute;s le, et rang&eacute; dans :");
		echo "</H3>";
                echo "<BR><BR><TABLE><th><th>Date d'entr&eacute;e</th><th>Local</th><th>Biblioth&egrave;que</th><th>Rang&eacute;e</th></tr>";
                while ($myrow = biblio_db_fetch_array($resultat)) 
                {	
			$date_in = $myrow["date_in"]; 
			$tab_mois = array('',_('janvier'),_('f&eacute;vrier'),_('mars'),_('avril'),_('mai'),_('juin'),_('juillet'),
				_('ao&ucirc;t'),_('septembre'),_('octobre'),_('novembre'),_('decembre'));
			ereg("(....)-(..)-(..)$",$date_in,$match);
	                $jour  = $match[3];
	                $mois  = sprintf("%d",$match[2]);
	                $annee = $match[1];
	                $date_in_str =  "$jour " . $tab_mois[$mois] . " $annee";         
			$location_ID = $myrow["location_ID"];
			$local  = $myrow["local"];
			$biblio   = $myrow["biblio"];
			$rangee = $myrow["rangee"];
	           	echo "<TR><TD>$date_in_str</TD><TD>$local</TD><TD ALIGN=RIGHT>$biblio</TD><TD ALIGN=RIGHT>$rangee</TD>";
			echo"<TD><A href=\"deltemp.php?action=del&date_in=$date_in&location_ID=$location_ID\"><IMG SRC=\"images/wh_r_arr.gif\" ALT=\"";
			echo _("effacer ces livres...");
			echo "\" border=0></A></TD>";
	        }
		echo "</TABLE>";
         }       
   }
  else
  {
       echo "<BR>";
       echo _("Les livres reçu en pr&ecirc;ts le $date_in ont &eacute;t&eacute; effac&eacute;s");
       echo "<BR><BR><U>";
       echo _("Voici la liste");
       echo "</U> :<BR><BR>";

       $requete = "select nom from livres where date_in = '" . $date_in . "' and location_ID=$location_ID order by nom";

       if(!($resultat = biblio_db_query($requete)))
       { print "PROBLEME $requete: " .biblio_db_error(); }
       while ($myrow = biblio_db_fetch_array($resultat)) 
       {
         print "<LI>" . $myrow["nom"];
       }
       print "<BR><BR><B>" . biblio_db_num_rows($resultat);
       if (biblio_db_num_rows($resultat) < 2) echo _(" livre a &eacute;t&eacute; effac&eacute;</b>");
       else echo _(" livres ont &eacute;t&eacute; effac&eacute;s</b>");
       $requete = "update livres set del=1 where date_in = '$date_in' and location_ID=$location_ID";
       if(!($resultat = biblio_db_query($requete)))
       { print "PROBLEME $requete: " .biblio_db_error(); }
       put_log(4,"LOGICAL ".$requete,$user); 
  }        
}
?>
</CENTER>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
<?php
include("includes/footer.inc");
?>
